package com.jackaltsc.mydemodatastorage.externalstorage;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.jackaltsc.mydemodatastorage.R;

public class ExternalActivity extends Activity implements OnClickListener {

    private Button btnSave, btnRead;

    private EditText etDataWrite;
    private TextView tvDataRead;

    private String dataWrite, dataRead;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_external);

        initView();

    }

    private void initView() {

        etDataWrite = (EditText) findViewById(R.id.et_datawrite);
        btnSave = (Button) findViewById(R.id.btn_save);
        tvDataRead = (TextView) findViewById(R.id.tv_dataread);
        btnRead = (Button) findViewById(R.id.btn_read);

        initEvent();

    }

    private void initEvent() {

        btnSave.setOnClickListener(this);
        btnRead.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.btn_save:
                dataWrite = etDataWrite.getText().toString();
                ExternalTools.funExternalWrite(dataWrite, ExternalTools.FILENAME);
                break;

            case R.id.btn_read:
                dataRead = ExternalTools.funExternalRead(ExternalTools.FILENAME);
                tvDataRead.setText(dataRead);
                break;
        }

    }
}
